define(['store'], function (store) {
    'use strict';
    function ctrl($scope, $state, $ionicLoading, LocalCacheService, CommonService, IdentificationService) {
        var oldEndDate = store.get('idCard2').idenddate;

        function init() {
            var user = LocalCacheService.getUser();
            $scope.idInfo = {
                name: user.client_name,
                identification: user.id_no,
                organization: store.get('idCard2').policeorg,
                address: store.get('idCard1').addr,
                start: store.get('idCard2').idbegindate,
                end: oldEndDate,
                validity: false
            };
        }

        $scope.$on('$ionicView.beforeEnter', function () {
            init();
        });

        $scope.changeValidity = function () {
            if ($scope.idInfo.validity) {
                $scope.idInfo.end = '3000-12-31';
            } else {
                $scope.idInfo.end = oldEndDate;
            }
        };

        $scope.check = function () {
            $ionicLoading.show();
            var iDate = {
                id_begindate: $scope.idInfo.start,
                id_enddate: $scope.idInfo.end
            };
            IdentificationService.uploadSumbit(iDate)
                .then(function (data) {
                    $ionicLoading.hide();
                    if (data.error_no != 0) {
                        CommonService.showAlert({message: data.error_info});
                        return;
                    }
                    $state.go('tab.account-userInfoVideo');
                }, function(result){
                    $ionicLoading.hide();
                    CommonService.showAlert({message: result.error_info});
                }
            );
        }
    }

    ctrl.$inject = ['$scope', '$state', '$ionicLoading','LocalCacheService', 'CommonService', 'IdentificationService'];
    return ctrl;
});